using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;


public class EditorBase : Editor
{
    protected T DefaultLayout<T>(string label,T value){
        T ret=default;
        if(value is int){
            int v=(int)Convert.ChangeType(value,typeof(int));
            ret=(T)Convert.ChangeType(EditorGUILayout.IntField(label,v),typeof(int));
        }else if (value is long)
        {
            long v = (long)Convert.ChangeType(value, typeof(long));
            ret = (T)Convert.ChangeType(EditorGUILayout.LongField(label, v), typeof(long));
        }else if (value is double)
        {
            double v = (double)Convert.ChangeType(value, typeof(double));
            ret = (T)Convert.ChangeType(EditorGUILayout.DoubleField(label, v), typeof(double));
        }else if (value is float)
        {
            float v = (float)Convert.ChangeType(value, typeof(float));
            ret = (T)Convert.ChangeType(EditorGUILayout.FloatField(label, v), typeof(float));
        }
        else if(value is LayerMask){
            LayerMask v = (LayerMask)Convert.ChangeType(value, typeof(LayerMask));
            List<string> layersName=new();
            for (int i = 0; i <32; i++)
            {
                layersName.Add(LayerMask.LayerToName(i));
            }
            int intV=EditorGUILayout.MaskField(label,v.value,layersName.ToArray());
            ret = (T)Convert.ChangeType((new LayerMask(){value=intV}),typeof(LayerMask));
        }else if (value is bool)
        {
            bool v = (bool)Convert.ChangeType(value, typeof(bool));
            ret = (T)Convert.ChangeType(EditorGUILayout.Toggle(label, v), typeof(bool));
        }
        else if (value is Enum)
        {
            Enum v = (Enum)Convert.ChangeType(value, typeof(Enum));
            ret = (T)Convert.ChangeType(EditorGUILayout.EnumPopup(label, v), typeof(Enum));
        }else if (value is Vector2)
        {
            Vector2 v = (Vector2)Convert.ChangeType(value, typeof(Vector2));
            ret = (T)Convert.ChangeType(EditorGUILayout.Vector2Field(label, v), typeof(Vector2));
        }
        else{
            throw new NotImplementedException();
        }
        return ret;
    }

    
}
